# -*- encoding:utf-8 -*-
from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1292051464.7981629
_template_filename=u'/Users/joeldunham/old/onlinelinguisticdatabase/templates/base/fileViews.html'
_template_uri=u'/base/fileViews.html'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding='utf-8'
from webhelpers.html import escape
_exports = ['displayAssociatedForms', 'displayAudio', 'fileView', 'displayVideo', 'displayTextual', 'displayFileMetaData', 'displayFileButtons', 'displayFile', 'fileViewShort', 'displayImage', 'insertAudioJavaScript']


# SOURCE LINE 1
 
from os import sep, path 
from random import randrange


def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        __M_writer = context.writer()
        # SOURCE LINE 4
        __M_writer(u' \n\n')
        # SOURCE LINE 10
        __M_writer(u'\n\n')
        # SOURCE LINE 23
        __M_writer(u'\n\n\n')
        # SOURCE LINE 35
        __M_writer(u'\n\n\n')
        # SOURCE LINE 63
        __M_writer(u'\n\n\n')
        # SOURCE LINE 72
        __M_writer(u'\n\n\n')
        # SOURCE LINE 88
        __M_writer(u'\n\n\n')
        # SOURCE LINE 96
        __M_writer(u'\n\n')
        # SOURCE LINE 103
        __M_writer(u'\n\n')
        # SOURCE LINE 115
        __M_writer(u'\n\n\n')
        # SOURCE LINE 120
        __M_writer(u'\n\n\n')
        # SOURCE LINE 126
        __M_writer(u'\n\n\n')
        # SOURCE LINE 146
        __M_writer(u'\n\n\n')
        # SOURCE LINE 175
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayAssociatedForms(context,file):
    context.caller_stack._push_frame()
    try:
        url = context.get('url', UNDEFINED)
        h = context.get('h', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 129
        __M_writer(u'\n')
        # SOURCE LINE 130
        for form in file.forms:
            # SOURCE LINE 131
            __M_writer(u'  <div class="associatedEntitiesDiv">\n  ')
            # SOURCE LINE 132
 
            maxLen = 20
            transcription = h.clip(form.grammaticality + form.transcription, maxLen)
            gloss = h.clip(form.glosses[0].glossGrammaticality + form.glosses[0].gloss, maxLen)
              
            
            # SOURCE LINE 136
            __M_writer(u'\n   Associated Form ')
            # SOURCE LINE 137
            __M_writer(escape(form.id))
            __M_writer(u':\n   <span class="emphasize">')
            # SOURCE LINE 138
            __M_writer(escape(h.storageToOutputTranslate(transcription)))
            __M_writer(u'</span> \n   &lsquo;')
            # SOURCE LINE 139
            __M_writer(escape(h.literal(gloss)))
            __M_writer(u'&rsquo;\n  <div class="containerDivIndent">\n   <a href="')
            # SOURCE LINE 141
            __M_writer(escape(url('disassociate', controller='file', id=file.id, otherID=form.id)))
            __M_writer(u'" class="buttonLink" title=\'')
            __M_writer(escape("Click to disassociate Form %s from File %s"%(form.id, file.id)))
            __M_writer(u'\'>disassociate</a> \n   <a href="')
            # SOURCE LINE 142
            __M_writer(escape(url(controller='form', action='view', id=form.id)))
            __M_writer(u'" class="buttonLink" title="')
            __M_writer(escape('Click to view more info about Form %s' % form.id))
            __M_writer(u'">view</a>\n  </div>\n  </div>\n')
            pass
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayAudio(context,file,fileReference):
    context.caller_stack._push_frame()
    try:
        self = context.get('self', UNDEFINED)
        str = context.get('str', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 105
        __M_writer(u'\n ')
        # SOURCE LINE 106
        __M_writer(escape(self.insertAudioJavaScript()))
        __M_writer(u'\n ')
        # SOURCE LINE 107
 
        fileName = file.name.replace('.', '_') 
        uniqueNo = str(randrange(0,1000))
        uniqueFileName = fileName + uniqueNo
         
        
        # SOURCE LINE 111
        __M_writer(u'\n <a class="buttonLink" title="click to show audio embedded in page" onclick="playAudio(\'')
        # SOURCE LINE 112
        __M_writer(escape(fileReference))
        __M_writer(u"', '")
        __M_writer(escape(fileName))
        __M_writer(u"', '")
        __M_writer(escape(file.MIMEtype))
        __M_writer(u"', '")
        __M_writer(escape(uniqueFileName))
        __M_writer(u'\')">play audio</a>\n <a href="')
        # SOURCE LINE 113
        __M_writer(escape(fileReference))
        __M_writer(u'" class="buttonLink" title="click to link to this audio file; right-click to download this audio file">link to audio</a>\t\n <div id="')
        # SOURCE LINE 114
        __M_writer(escape(uniqueFileName))
        __M_writer(u'" class="embeddedAudioDiv"></div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_fileView(context,file):
    context.caller_stack._push_frame()
    try:
        self = context.get('self', UNDEFINED)
        app_globals = context.get('app_globals', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 12
        __M_writer(u'\n')
        # SOURCE LINE 13
        if app_globals.allowedFileTypes[file.MIMEtype]:
            # SOURCE LINE 14
            __M_writer(u'        ')
            fileType = app_globals.allowedFileTypes[file.MIMEtype] 
            
            __M_writer(u'\n')
            # SOURCE LINE 15
        else: 
            # SOURCE LINE 16
            __M_writer(u'        ')
            fileType = file.MIMEtype.split('/')[0] 
            
            __M_writer(u'\n')
            pass
        # SOURCE LINE 18
        __M_writer(u'    ')
        __M_writer(escape(self.displayFileMetaData(file, fileType)))
        __M_writer(u'\n    ')
        # SOURCE LINE 19
        __M_writer(escape(self.displayAssociatedForms(file)))
        __M_writer(u'\n    ')
        # SOURCE LINE 20
        __M_writer(escape(self.displayFileButtons(file)))
        __M_writer(u'\n    ')
        # SOURCE LINE 21
        __M_writer(escape(self.displayFile(file, fileType)))
        __M_writer(u'\n    <div class="tableSpacerDiv"></div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayVideo(context,file,fileReference):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 118
        __M_writer(u'\nvideo to be displayed...\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayTextual(context,file,fileReference):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 123
        __M_writer(u'\n  ')
        # SOURCE LINE 124
        fileExtension = file.name.split('.')[-1] 
        
        __M_writer(u'\n  <a href="')
        # SOURCE LINE 125
        __M_writer(escape(fileReference))
        __M_writer(u'" class="buttonLink" title="right-click to download this ')
        __M_writer(escape(fileExtension))
        __M_writer(u' file">link to text</a>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayFileMetaData(context,file,fileType):
    context.caller_stack._push_frame()
    try:
        h = context.get('h', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 38
        __M_writer(u'\n    <table class="fileTable">\n    <tr><td class="fileTableRowLabel">ID</td><td class="dataCell">')
        # SOURCE LINE 40
        __M_writer(escape(file.id))
        __M_writer(u'</td></tr>\n    <tr><td class="fileTableRowLabel">name</td><td class="dataCellTr">')
        # SOURCE LINE 41
        __M_writer(escape(file.name))
        __M_writer(u'</td></tr>\n    <tr><td class="fileTableRowLabel">type</td><td class="dataCell">')
        # SOURCE LINE 42
        __M_writer(escape(fileType))
        __M_writer(u'</td></tr>\n    <tr><td class="fileTableRowLabel">size</td><td class="dataCell">')
        # SOURCE LINE 43
        __M_writer(escape(h.pretty_filesize(file.size)))
        __M_writer(u'</td></tr>\n')
        # SOURCE LINE 44
        if file.description:
            # SOURCE LINE 45
            __M_writer(u'    <tr><td class="fileTableRowLabel">description</td><td class="dataCell">')
            __M_writer(escape(file.description))
            __M_writer(u'</td></tr>\n')
            pass
        # SOURCE LINE 47
        if file.utteranceType:
            # SOURCE LINE 48
            __M_writer(u'    <tr><td class="fileTableRowLabel">utterance type</td><td class="dataCell">')
            __M_writer(escape(file.utteranceType))
            __M_writer(u'</td></tr>\n')
            pass
        # SOURCE LINE 50
        __M_writer(u'    <tr><td class="fileTableRowLabel">enterer</td><td class="dataCell">')
        __M_writer(escape(file.enterer.firstName))
        __M_writer(u' ')
        __M_writer(escape(file.enterer.lastName))
        __M_writer(u'</td></tr>\n')
        # SOURCE LINE 51
        if file.speaker:
            # SOURCE LINE 52
            __M_writer(u'    <tr><td class="fileTableRowLabel">speaker</td><td class="dataCell">')
            __M_writer(escape(file.speaker.firstName))
            __M_writer(u' ')
            __M_writer(escape(file.speaker.lastName))
            __M_writer(u'</td></tr>\n')
            pass
        # SOURCE LINE 54
        if file.elicitor:
            # SOURCE LINE 55
            __M_writer(u'    <tr><td class="fileTableRowLabel">elicitor</td><td class="dataCell">')
            __M_writer(escape(file.elicitor.firstName))
            __M_writer(u' ')
            __M_writer(escape(file.elicitor.lastName))
            __M_writer(u'</td></tr>\n')
            pass
        # SOURCE LINE 57
        if file.dateElicited:
            # SOURCE LINE 58
            __M_writer(u'    <tr><td class="fileTableRowLabel">date elicited</td><td class="dataCell">')
            __M_writer(escape(file.dateElicited.strftime('%b %d, %Y')))
            __M_writer(u'</td></tr>\n')
            pass
        # SOURCE LINE 60
        __M_writer(u'    <tr><td class="fileTableRowLabel">time entered</td><td class="dataCell">')
        __M_writer(escape(file.datetimeEntered.strftime('%b %d, %Y at %I:%M %p')))
        __M_writer(u'</td></tr>\n    <tr><td class="fileTableRowLabel">last updated</td><td class="dataCell">')
        # SOURCE LINE 61
        __M_writer(escape(file.datetimeModified.strftime('%b %d, %Y at %I:%M %p')))
        __M_writer(u'</td></tr>\n    </table>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayFileButtons(context,file):
    context.caller_stack._push_frame()
    try:
        url = context.get('url', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 66
        __M_writer(u'\n  <div class="fileButtonsDiv">\n    <a href="')
        # SOURCE LINE 68
        __M_writer(escape(url(controller='file', action='update', id=file.id)))
        __M_writer(u'" class="buttonLink" title="Edit this File\'s data">update</a>\n    <a href="')
        # SOURCE LINE 69
        __M_writer(escape(url(controller='file', action='delete', id=file.id)))
        __M_writer(u'" class="buttonLink" onclick="return confirmDelete(\'File\', ')
        __M_writer(escape(file.id))
        __M_writer(u')" title="Delete this File; confirmation will be requested">delete</a>\n    <a href="')
        # SOURCE LINE 70
        __M_writer(escape(url(controller='file', action='associate', id=file.id)))
        __M_writer(u'" class="buttonLink" title="Associate one or more Forms to this File">associate</a>\n  </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayFile(context,file,fileType):
    context.caller_stack._push_frame()
    try:
        url = context.get('url', UNDEFINED)
        self = context.get('self', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 75
        __M_writer(u'\n ')
        # SOURCE LINE 76
        fileReference = url('retrieve', path=file.name) 
        
        __M_writer(u'\n <div class="fileContent">\n')
        # SOURCE LINE 78
        if fileType == 'image':
            # SOURCE LINE 79
            __M_writer(u'    ')
            self.displayImage(file, fileReference) 
            
            __M_writer(u'\n')
            # SOURCE LINE 80
        elif fileType == 'audio':
            # SOURCE LINE 81
            __M_writer(u'    ')
            self.displayAudio(file, fileReference) 
            
            __M_writer(u'\n')
            # SOURCE LINE 82
        elif fileType == 'video':
            # SOURCE LINE 83
            __M_writer(u'    ')
            self.displayVideo(file, fileReference) 
            
            __M_writer(u'\n')
            # SOURCE LINE 84
        else:
            # SOURCE LINE 85
            __M_writer(u'    ')
            self.displayTextual(file, fileReference) 
            
            __M_writer(u'\n')
            pass
        # SOURCE LINE 87
        __M_writer(u' </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_fileViewShort(context,file):
    context.caller_stack._push_frame()
    try:
        self = context.get('self', UNDEFINED)
        app_globals = context.get('app_globals', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 26
        __M_writer(u'\n')
        # SOURCE LINE 27
        if app_globals.allowedFileTypes[file.MIMEtype]:
            # SOURCE LINE 28
            __M_writer(u'        ')
            fileType = app_globals.allowedFileTypes[file.MIMEtype] 
            
            __M_writer(u'\n')
            # SOURCE LINE 29
        else: 
            # SOURCE LINE 30
            __M_writer(u'        ')
            fileType = file.MIMEtype.split('/')[0] 
            
            __M_writer(u'\n')
            pass
        # SOURCE LINE 32
        __M_writer(u'    ')
        __M_writer(escape(self.displayFileMetaData(file, fileType)))
        __M_writer(u'\n    ')
        # SOURCE LINE 33
        __M_writer(escape(self.displayFile(file, fileType)))
        __M_writer(u'\n    <div class="tableSpacerDiv"></div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_displayImage(context,file,fileReference):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 91
        __M_writer(u'\n  ')
        # SOURCE LINE 92
        fileName = path.splitext(file.name)[0] 
        
        __M_writer(u'\n  ')
        # SOURCE LINE 93
        buttonID = fileName + 'Button' 
        
        __M_writer(u'\n  <a onclick="addRemoveElement(\'')
        # SOURCE LINE 94
        __M_writer(escape(fileName))
        __M_writer(u"', '")
        __M_writer(escape(buttonID))
        __M_writer(u'\', \'image\', \'hide image|show image\');" class="buttonLink" id="')
        __M_writer(escape(buttonID))
        __M_writer(u'" title="show image embedded in the page">show image</a>\n  <img alt="')
        # SOURCE LINE 95
        __M_writer(escape(file.name))
        __M_writer(u'" style="display:none;" src="')
        __M_writer(escape(fileReference))
        __M_writer(u'" class="imageFile" id="')
        __M_writer(escape(fileName))
        __M_writer(u'" />\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_insertAudioJavaScript(context):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 149
        __M_writer(u'\n <script type="text/javascript">\n  function playAudio(fileReference, fileName, MIMEtype, uniqueFileName)\n  {\n      var embeddedAudioDiv = document.getElementById(uniqueFileName);\n      var useAudioTag = canUseHTMLAudioTag(MIMEtype);\n      embeddedAudioDiv.style.display="block";\n      embeddedAudioDiv.style.display="visible";\n      if (useAudioTag)\n      {\n          embeddedAudioDiv.innerHTML = \'<audio src="\' + fileReference + \'" controls="controls"></audio>\';\n      }\n      else\n      {\n          output = \'<embed src="\' + fileReference + \'" autoplay="false" autostart="false" width="300" height="30" />\\n\'\n          /*output += "<span class=\'error-message\'>Sorry, your browser does not fully support embedding of this audio file type.  As a result, the above audio player may not work properly.  Try right-clicking on the &ldquo;link to audio&rdquo; button to open this file in a new tab or to download this file.</span>";*/\n          embeddedAudioDiv.innerHTML = output;\n      }\n  }\n  function canUseHTMLAudioTag(MIMEtype)\n  {\n      var audio  = document.createElement("audio");\n      canPlayMIMEtype = (typeof audio.canPlayType === "function" && audio.canPlayType(MIMEtype) !== "");\n      return(canPlayMIMEtype);\t\n  }\n </script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


